<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ include file="/WEB-INF/jsp/component/common.jsp" %>
<html>
<head>
    <title>血压筛查</title>
    <link rel="stylesheet" href="${frames}/css/lib/bootstrap.min.css" type="text/css">
    <link rel="stylesheet" href="${frames}/css/lib/dataTables.bootstrap.css" type="text/css">
    <%--<link rel="stylesheet" href="${frames}/css/paginate.css" type="text/css">--%>
    <%--<link rel="stylesheet" href="${frames}/css/qulitity.css" type="text/css">--%>
    <link rel="stylesheet" href="../assets/css/views/modules/_common.scss">
    <link rel="stylesheet" href="${newframe}/css/base/base.css" type="text/css">
    <link rel="stylesheet" href="${assets}/css/views/bloodScreening.css">
    <link rel="stylesheet" href="${assets}/css/views/department/departmentMgr.css">
    <script src="../assets/js/views/vue.min.js"></script>
    <script src="${js}/jquery-1.9.1.min.js"></script>
    <script src="${frames}/Chronic/laydate/laydate.js"></script>
    <%@ include file="/WEB-INF/jsp/component/commonBottom.jsp" %>
    <style>
        .color{
            margin:0 !important;
        }
        .btn{
            float:right ;
            width:100px;
            font-size:16px;
            line-height:28px;
            background:#35acfd !important;
            margin-right:15px !important;
            padding:0 !important;
        }
        .infor div span{
            color:#666;
        }
        .infor .other span{
            width:40.7%;
            margin-right:5.36%;
        }
        #example_paginate{
            margin-top:15px;
            width:100%;
            text-align: center;
        }
        #mytool{
            width:96%;
        }
        .highMax{
            color:#ff1319;
        }
        .lowMax{
            color: #f69f40;
        }
        .dataTables_empty{
            line-height:30px;
        }
        span{
            font-family:MicrosoftYaHei-Bold;
            font-weight:normal;
            font-stretch:normal;
            letter-spacing:0px;
        }
    </style>
</head>
<body>
<div>
    <%@ include file="../../breadline.jsp" %>
</div>
<div id="main" class="wrap">
    <div style="width:100%;">
        <div>
            <%@ include file="../../personalnews.jsp" %>
        </div>
        <div class="illness">
            <div class="tableWrap">
                <div style="margin-left:20px;padding-top:20px;">
                    <h3 style="margin-bottom:16px;">筛查记录</h3>
                </div>
                <div class="form">
                    <div id="date" style="float: left">
                        <label>时间:</label>
                        <input id="beginDate" type="text" class="lay-date" placeholder="起始时间" readonly>
                        <label> — </label>
                        <input id="endDate" type="text" class="lay-date" placeholder="截止时间" readonly>
                    </div>
                    <button class="search" id="query" onclick="refreshTable();">搜索</button>
                </div>
                <div class="content" style="padding-bottom:40px;">
                    <div id="tablepart">
                        <table id="example" class="display" cellspacing="10" width="100%">
                            <thead>
                            <tr style="background:#e6e6e6;">
                                <th></th>
                                <th>筛查时间</th>
                                <th>收缩压(mmHg)</th>
                                <th>舒张压(mmHg)</th>
                                <th>管理级别</th>
                            </tr>
                            </thead>
                        </table>
                        <%--<p v-show="test" style="text-align:center;line-height:40px;font-size:14px;">暂无数据</p>--%>
                    </div>
                </div>
                <div class="loading" style="display: none;">
                    <img src="${newframe }/images/slidebar/loading.gif" class="loadingImg">
                </div>
            </div>

        </div>
    </div>
</div>
<script>
    var vm = new Vue({
        el : "#main",
        data: {
            infor: [],//病人基本信息data
            id:'',
            idCard:'',
            BMI:'',
            age:'',
            ispatient:'',
            highBp:'',
            isObesity:'',
            familyHistory:'',
            isHighSalt:'',
            isExcessive:'',
            isGreater:'',
            test:true,
            check:true,
            type:'',
            synchronous:false,
            btnText:'',
            dis:false
        },
        methods:{
            //修改病人基本信息
            addDevice:function(){
                let that = this;
                window.parent.showNewModelIframe("${URL_PATIENT_PATIENT}?id="+that.infor.id+'&diseasesType='+that.type,800,650);
            },
            Synchronous(e){
                let that = this
                $.ajax({
                    url:'${URL_PATIENT_UPDATEPATIENT}',
                    data:{
                        id:that.infor.id,
                        synchronization:'1'
                    },
                    type:'post',
                    dataType:'json',
                    success:function(data){
                        console.log(data)
                        if(data.success){
                            e.target.disabled = true;
                            e.target.innerText = '正在同步'
                            that.setTime()
                        }else{
                            window.parent.showNewModelIframe('${URL_COMMON_TOTIPS}?title='+data.msg,300,200)
                        }
                    }
                })
            },
            setTime(){
                let that = this
                setInterval(function(){
                    $.ajax({
                        url:'${URL_PATIENT_UPDATEPATIENT}',
                        data:{
                            id:that.infor.id,
                            synchronization:'1'
                        },
                        type:'post',
                        dataType:'json',
                        success:function(data){

                        }
                    })
                },10000)
            }
        },
        mounted() {
            let that = this;
            var href = location.search.split('?')[1];
            var arr = href.split('&')[0];
            var url = arr.split('=')[1];
            var add = location.search.split('?')[1].split('&')
            that.type = location.search.split('?')[1].split('&')[add.length -1 ].split('=')[1]
            // 获取病人基本信息
            $.ajax({
                url:"${URL_PATIENT_PATIENTINFO}",
                type:'post',
                dataType: "json",
                data:{
                    idCard:"${idcard}"
                },
                success: function(data) {
                    that.infor = data.data;
                    var href = that.infor.diseasesType
                    that.infor.diseasesType = Type(that.infor.diseasesType)
                    that.id=that.infor.id;
                    that.idCard=url;
                    sessionStorage.setItem('BMI',that.infor.bMI);
                    sessionStorage.setItem('age',that.infor.age);
                }
            })

        }
    })
    function initTable() {
        var url="${URL_SCREENING_BPLIST}?idCard="+"${idcard}";
        table = $('#example').DataTable({
            "dom": "<'row'<'#mytool.col-xs-10'><'col-xs-6'f>r>" +
                "t" +
                "<'row'<''i><''p>>",
            "bFilter": false,//去掉搜索框
            "bAutoWidth": true, //自适应宽度
            "info": false,
            "bSort": false,
            "sPaginationType" : "full_numbers",
            "ordering": false,//是否允许Datatables开启排序
            "bProcessing" : true,
            "bServerSide" : true,
            "searching" : false, //去掉搜索框方法一
            'lengthChange' : false,
            "oPaginate":false,
            "sAjaxSource":url,
            "sAjaxDataProp": "dataList",//查询后，返回的集合
            "fnServerData": function ( sSource, aoData, fnCallback ) {
                aoData.push(
                    {
                        "name" : "startTime",
                        "value" : $("#beginDate").val()
                    },{
                        "name" : "endTime",
                        "value" : $("#endDate").val()
                    }
                );
                $.ajax( {
                    "dataType": 'json',
                    "url": sSource,
                    "type":'post',
                    "data":aoData,
                    "success": function(resp){
                        fnCallback(resp)
                        console.log(resp);
                    }
                    });
            },
            "aoColumns" : [{
                "targets": 0,
                "data": null,
                "fnCreatedCell" : function(nTd, sData, oData, iRow, iCol) {
                    $(nTd).html(
                            ''
                            + '&nbsp;&nbsp;<input name="id" class="check_id" id = "'+oData.id + '" value="'
                            + oData.id
                            + '" type="checkbox"><label for='+oData.id+'></label>'
                            + '');
                }
            },{
                "mDataProp" : "screeningTime"
            },{
                "targets": 2,
                "data": null,
                "fnCreatedCell" : function(nTd, sData, oData, iRow, iCol) {
                    if(parseInt(oData.highPressure)>=parseInt(oData.highMaxValue)){
                        $(nTd).html(
                            ''
                            + '<span class="highMax" >'+oData.highPressure+ '</span>'
                            + '');
                    }else{
                        $(nTd).html(
                            ''
                            + '<span class="" >'+oData.highPressure+ '</span>'
                            + '');
                    }
                }
            },{
                "targets": 3,
                "data": null,
                "fnCreatedCell" : function(nTd, sData, oData, iRow, iCol) {
                    if(parseInt(oData.lowPressure)>=parseInt(oData.lowMaxValue)){
                        $(nTd).html(
                            ''
                            + '<span class="lowMax" >'+oData.lowPressure+ '</span>'
                            + '');
                    }else{
                        $(nTd).html(
                            ''
                            + '<span class="" >'+oData.lowPressure+ '</span>'
                            + '');
                    }
                }
            },{
                "targets": 4,
                "data": null,
                "fnCreatedCell" : function(nTd, sData, oData, iRow, iCol) {
                    if(oData.level=='1'){
                        $(nTd).html(
                            ''
                            + '<span>一级</span>'
                            + '');
                    } else if (oData.level=='2') {
                        $(nTd).html(
                            ''
                            + '<span>二级</span>'
                            + '');
                    } else {
                        $(nTd).html(
                            ''
                            + '<span>三级</span>'
                            + '');
                    }
                }
            }],
            "oLanguage": {//插件的汉化
                "sLengthMenu": "32",
                "sInfoEmpty" : "没有数据",
                "sInfoFiltered" : "(从 _MAX_ 条数据中检索)",
                "oPaginate" : {
                    "sFirst" : "",
                    "sPrevious" : "<b>上一页<b>",
                    "sLast" : "",
                    "sNext" : "<i>下一页</i>"

                },
                "sZeroRecords" : "没有检索到数据",
                "sProcessing" : "<img src='' />",
                "sSearch" : "搜索"
            },
            "initComplete" : function() {
                $("#mytool")
                    .append(
                        '<button id="delete_butt" type="button" onclick="deleteInstr()" style="float:right">删除</button>');
                $("#mytool")
                    .append(
                        '<button id="update_butt" type="button" onclick="updateInfo()" style="float:right">修改</button>');
                $("#mytool")
                    .append(
                        '<button id="delete_butt" type="button" onclick="addInfo()" style="float:right">增加</button>');
            }

        });
    }
    $(document).ready(function() {
        initTable();
        // 初始化日历
        initLayDate('#beginDate');
        initLayDate('#endDate');

    })
    function initLayDate(id) {
        laydate({
            elem: id,
            istime: true,
            format: 'YYYY-MM-DD',
            choose: function (dates) { //选择好日期的回调
                // initTablePatient();
            }
        })
    }
    function updateInfo(obj){
        var checkedArray = getCheckedArray();
        var pBMI=sessionStorage.getItem('BMI');
        var pAge=sessionStorage.getItem('age');
        var input = $('.check_id');

        if (checkedArray.length != 1) {
            alert("请勾选一条数据修改");
            return;
        }else{
            parent.showSrc('${URL_SCREENING_BPSCREENING}?idcard=' + '${idcard}'+ '&id=' +checkedArray[0]);

        }

    }
    function deleteInstr() {
        var checkedArray = getCheckedArray();
        var ids = "";
        if (checkedArray.length == 0) {
            alert("请勾选至少一项数据");
            return;
        } else {
            for (var i = 0; i < checkedArray.length; i++) {
                ids += checkedArray[i] + ",";
            }
            ids = ids.substring(0, ids.length - 1);
        }
        var r = confirm("确定要删除勾选的数据吗?");
        if (r == true) {
            $.ajax({
                url : '${URL_SCREENING_DELETEBP}',//删除地址
                dataType : 'json',
                type : 'post',
                data : {
                    ids : ids
                },
                async : false, //默认为true 异步
                error : function() {
                    alert('error');
                },
                success : function(data) {

                    if (!data.success) {
                        alert("刪除失敗，失敗原因：" + data.msg);
                    }
                    refreshTable();
                }
            });
        }
    }
    function getCheckedArray() {
        var checkedArray = [];
        $("input[name='id']").each(function() {
            if (this.checked) {
                checkedArray.push(this.value);
            }
        });
        return checkedArray;
    }
    function addInfo() {
        parent.showSrc('${URL_SCREENING_BPSCREENING}?idcard=' + '${idcard}');
    }
</script>
</body>
</html>
